#pragma once

#include "event/my_aio_req.h"
#include "event/my_event.h"
#include "cache/util/my_cache_req.h"


typedef struct my_disk_data_s my_disk_data_t;
typedef struct my_disk_key_lock_node_s my_disk_key_lock_node_t;

typedef struct my_disk_write_context_s my_disk_write_context_t;

typedef void(*my_disk_write_context_handler_pt)(my_disk_write_context_t *context);

struct my_disk_write_context_s {
    my_cache_req_t                      *req;
    my_disk_key_lock_node_t             *lock_node;
    int64_t                             old_offset; // for reinsert operation

    // save disk_volume
    void                                *ctx_data;
    my_disk_write_context_handler_pt    handler;

    my_disk_data_t                      *disk_data;
    int64_t                             object_size;
    int64_t                             aligned_size;
    uint32_t                            crc32;

    int64_t                             retry_count;

    // write cursor for switch active buf
    my_disk_vinfo_write_cursor_t        write_cursor;
    my_disk_buf_t                       *active_buf;
    int64_t                             offset_in_buffer;


    int64_t                             offset;
    uint8_t                             write_serial;                     
};

static inline void
my_disk_write_context_init(my_disk_write_context_t *context) {
    bzero(context, sizeof(my_disk_write_context_t));
}

typedef struct my_disk_read_context_s my_disk_read_context_t;

typedef void(*my_disk_read_context_handler_pt)(my_disk_read_context_t *context);

struct my_disk_read_context_s {
    my_cache_req_t                      *req;
    my_disk_key_lock_node_t             *lock_node;

    // save disk_volume
    void                                *ctx_data;
    my_disk_read_context_handler_pt     handler;

    my_disk_data_t                      *disk_data;
    uint8_t                             write_serial;
    int64_t                             offset;
    int64_t                             aligned_size;   // aligned(object size)
    my_buf_t                            *buf;           // alloc buf for read file

    my_aio_req_t                        aio_req;
};

static inline void
my_disk_read_context_init(my_disk_read_context_t *context) {
    bzero(context, sizeof(my_disk_read_context_t));
}